Skip to content

fix(server): early requests get a 503 again instead of hanging until startup ends - #41627

Open
juliusmarminge wants to merge 1 commit into
mainfrom
perf/startup-ready
Open

juliusmarminge wants to merge 1 commit into
mainfrom
perf/startup-ready

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

Problem

The server-metrics A/B of v0.1.11 (59651c1761f) against main (f58085a1c2e) flagged startup.readyMs as worse on both machines:

  • Linux (16 cores): 7,045 → 9,895 ms (+40%), 95% interval +2,536 to +3,389 ms
  • Windows (4 vCPU): 4,349 → 5,647 ms (+30%)

Module loading, migrations and layer construction take about the same time on both sides; the server starts listening at about the same moment (~7.2 s after spawn on cups in both). The difference is what happens to a request after that. On v0.1.11 the first GET / gets an immediate 503. On main it hangs until serve() attaches the router about 2 s later, so a client polling with a 1 s timeout only gets through on a later retry.

Cause

Effect 4.1.5 (#40132) changed NodeHttpServer.make to add its own request listener before it listens. That listener answers 503 only while it is the sole request listener. rejectRequestsUntilServing treats any new request listener as the serving handler and removes its own 503 handler. So Effect's listener removed ours, ours stopped answering, and Effect's stayed silent because the write-error and keep-alive listeners are still attached. Early requests and upgrades got no answer at all.

Fix

The handoff in rejectRequestsUntilServing starts only once the server is listening, so only serve() takes over. The new test runs the guards through the real NodeHttpServer.make. Without the fix the early request hangs until the test times out.

Before / after

node scripts/server-metrics.ts ab --only startup --rounds 3, before f58085a1c2e, after this branch, cups (linux-x64). Another benchmark was running on the machine, which is why the absolute numbers are higher than the audit's:

metric before after change 95% interval
startup.readyMs 10,154 7,797 -23% -2,453 to -2,130

A probe run the same way as the harness on the same machine: v0.1.11 ~9.6 s, main ~12.6 s, this branch ~9.9 s. That puts this branch back at the v0.1.11 level.

Investigated and fixed by Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

…startup ends

Since Effect 4.1.5, NodeHttpServer adds its own request listener before it
listens. rejectRequestsUntilServing treated that as the serving handler and
removed its 503, while the Effect fallback stays silent because other
request listeners exist. Requests during startup then hung until serve()
attached, so a client polling with a 1 s timeout only got through on a
later retry. The handoff now starts only once the server is listening.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: 1002934 · PR result: 5c743b7 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The guard now avoids handing off its fallback listener before the server listens. An integration test checks that requests receive 503 with Retry-After: 1 before serving and 204 after serving begins.

Changes: Startup response guard

Layer / File(s) Summary
Listener handoff and startup coverage
apps/server/src/httpResponseErrorGuard.ts, apps/server/src/httpResponseErrorGuard.test.ts
The newListener handler returns while the server is not listening. The updated comments describe the fallback and listener handoff. An integration test checks responses before and after serving starts.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • Issue 35995 — The PR changes the startup 503 guard behavior. The issue’s requests about migration duration and progress reporting are not covered.
Merge Risk: Minimal · up to 5c743

This change restores immediate 503 responses with Retry-After during server startup by deferring the listener handoff until the server is listening. No concrete merge-blocking risk was found, and an integration test covers the behavior before and after serving begins.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (early requests get a 503 again instead of hanging during startup) and the area (server). This matches the main change: rejectRequestsUntilServing now hands off only after the …
Description check Passed The description covers Problem, Cause, Fix, and a before/after benchmark, and it follows the template's intent of explaining the bug and its fix. It has the template's core sections in substance, but …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix (early requests get a 503 again instead of hanging during startup) and the area (server). This matches the main change: rejectRequestsUntilServing now hands off only after the server listens, restoring the immediate 503 that the raw summary and objectives describe. The title is specific, follows conventional commit form, and is one sentence.

Full details: Description check

Explanation

The description covers Problem, Cause, Fix, and a before/after benchmark, and it follows the template's intent of explaining the bug and its fix. It has the template's core sections in substance, but it uses different headings and lacks a linked issue or a clear statement that a maintainer requested the PR or why no issue is needed. The Scope section is missing its issue link or justification. The Verification section describes a new test and a benchmark, but it does not name the test or the exact test command, and it does not say what was not checked. The model/harness attribution is present. These gaps are non-critical, so the description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1002934 and 5c743b7.

Files selected for processing: 2

  • apps/server/src/httpResponseErrorGuard.test.ts
  • apps/server/src/httpResponseErrorGuard.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant